<template>
  <div class="info-container">
    <el-card style="height: 100%">
      <search-tool @onSearch="handleSearch"></search-tool>

      <el-table
        v-loading="loading"
        :data="tableData"
        :default-sort="{
          prop: 'repairTime',
          order: 'descending'
        }"
        style="width: 100%"
        height="75%"
      >
        <el-table-column label="序号" type="index" width="80" />
        <el-table-column prop="workOrderNo" label="工单编号"></el-table-column>
        <el-table-column
          prop="equipmentName"
          label="设备名称"
        ></el-table-column>
        <el-table-column prop="assetType" label="资产类型"> </el-table-column>
        <el-table-column prop="repairType" label="维护类型"> </el-table-column>
        <el-table-column prop="maintainPersonnel" label="维护人员">
        </el-table-column>
        <el-table-column
          prop="repairTime"
          label="维护时间"
          :sortable="'custom'"
          width="180"
        >
        </el-table-column>
        <el-table-column prop="pipeName" label="所属管廊"> </el-table-column>
        <el-table-column prop="storehouseName" label="所属仓室">
        </el-table-column>
        <el-table-column prop="subregionName" label="防火分区">
        </el-table-column>
        <el-table-column prop="repairDescription" label="维护说明">
        </el-table-column>
      </el-table>

      <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[5, 10, 20]"
        :page-size="size"
        layout="prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import SearchTool from './components/SearchTool/index.vue'
import { repairInfoList } from '@/api/back'

// //数据相关
const tableData = ref([])
const total = ref(0)
const page = ref(1)
const size = ref(8)
const params = ref({})
const loading = ref(false)
const visibleDialog = ref(false)

//获取数据的方法
const getListData = async (params) => {
  loading.value = true
  const result = await repairInfoList(params, page.value, size.value)
  loading.value = false
  tableData.value = result.rows
  total.value = result.total
}
// console.log(tableData.value)

const reloadPage = () => {
  getListData(params.value)
  if (visibleDialog.value) {
    visibleDialog.value = false
  }
}

reloadPage()
//查询条件相关
const handleSearch = (paramsData) => {
  params.value = paramsData
  getListData(paramsData)
}

// 分页相关
/**
 * size 改变触发
 */
const handleSizeChange = (currentSize) => {
  size.value = currentSize
  getListData(params.value)
}

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  page.value = currentPage
  getListData(params.value)
}
</script>

<style lang="scss" scoped>
.info-container {
  width: 100%;
  height: 100%;
  :deep(.el-table .caret-wrapper) {
    display: none;
  }
  .action-row {
    display: flex;
  }
  .pagination {
    width: 100%;
    height: 32px;
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: end;
  }
}
</style>
